#include "board.h"
#include "memory/at24c02.h"
#include <stdint.h>
#include <stdio.h>

int main_test(void)
{
	int i = 0;
	int ret = 0;
	int cnt = 0;
	int address = 0;
	uint8_t buffer[256];
	at24c02_t eeprom;

	board_init();

	eeprom.cfg.fix.device_address = 0x50;
	eeprom.ops.i2c_read = board_i2c_read;
	eeprom.ops.i2c_write = board_i2c_write;

	for (i = 0; i < 256; i++) {
		buffer[i] = i;
	}

	for (i = 0; i < 32; i++) {
		address = 8 * i;
		ret = at24c02_page_write(&eeprom, address, &buffer[address], 8);
		if (ret) {
			printf("err: at24c02_page_write, ret = %d\r\n", ret);
		}
	}
	printf("format is successful\r\n");

	for (i = 0; i < 256; i++) {
		buffer[i] = 0;
	}

	ret = at24c02_continuous_read(&eeprom, 0x00, buffer, 256);
	if (ret) {
		printf("err: at24c02_sequential_read, ret = %d\r\n", ret);
	}

	/* 打印提示信息 */
	printf("\r\n\t");
	for (i = 0; i < 16; i++) {
		printf("col %d\t", i);
	}
	printf("\r\n");

	printf("1\t");
	for (i = 0; i < 256; i++) {
		printf(" 0x%02x\t", buffer[i]);
		if (i % 16 == 15 && i < 255) {
			printf("\r\n");
			printf("0x%02x\t", i + 1);
		}
	}
	printf("\r\n");

	buffer[0] = 0x88;
	at24c02_byte_write(&eeprom, 0x00, buffer);

	buffer[0] = 0;
	at24c02_random_read(&eeprom, 0x00, buffer);

	while (1) {
		printf("hello at24c02 test %d!\r\n", cnt++);
		delay_ms(1000);
	}
}
